package com.wanqing.community.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.wanqing.community.bean.UserBean;
import com.wanqing.community.dao.UserLoginDao;
import com.wanqing.community.dao.util.MyBatisDao;
import com.wanqing.community.util.ConditionParse;

/**
 * 用户表Dao层实现类
 *  
 * All right reserved.
 * @version 
 * Company 
 */
@Repository("userLoginDao")
public class UserLoginDaoImpl extends MyBatisDao<UserBean, String> implements UserLoginDao {
	
	private final String NAMES_SPACE = "com.wanqing.community.bean.UserLoginBean";

	/**
	 *<p>Description:添加用户<p>
	 * <p>modifiContent:</p>
	 * @param list
	 * @return int
	 */
	public int addUserLogin(UserBean user) {		
		return this.save(NAMES_SPACE+".addUser", user);
	}

	/**
	 *<p>Description:根据电话号码查询，判断是否重复<p>
	 * <p>modifiContent:</p>
	 * @param list
	 * @return int
	 */
	public int getUserCounts(ConditionParse condParse) {		
		return this.getCount(NAMES_SPACE+".getUserCounts", condParse);
	}
	
 
 	 /**
 	  * 
 	  *<p>Description:修改用户<p>
 	  * <p>modifiContent:</p>
 	  * @param user
 	  * @return
 	  */
	public int updateUserLogin(UserBean user){
		return this.update(NAMES_SPACE+".updateUser", user);
	}
	
	/**
	 * 
	 *<p>Description:删除用户<p>
	 * <p>modifiContent:</p>
	 * @param list
	 * @return
	 */
	public int deleteUserLogin(List<String> list) {
		
		return this.deleteBatchById(NAMES_SPACE+".deleteUser", list);
	}
	
	public int getUserCount(ConditionParse condParse) {		
		return this.getCount(NAMES_SPACE+".getUserCount", condParse);
	}
	
	public List<UserBean> queryUser(ConditionParse condParse,
			int currPage, int pageSize) {		
		return this.queryForList(NAMES_SPACE+".queryUserPage", condParse, currPage, pageSize);
	}
	
	public UserBean findUserById(String id) {		
		return this.findObjectById(NAMES_SPACE+".findUserById", id);
	}
	
	public UserBean findUserByRoleId(String roleId) {
		return this.findObjectById(NAMES_SPACE+".findUserByRoleId", roleId);
	}
	 /**
	  * <p>Description:用户登录<p>
	  * <p>modifiContent:<p>
	  * @param loginName
	  * @param loginPwd
	  * @return
	  */
	public UserBean userLoign(String loginName, String loginPwd) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userName", loginName);
		map.put("password", loginPwd);
		return this.queryForEntity(NAMES_SPACE+".userLogin", map);
	}	
	public int deleteUser(ConditionParse condParse) {		
		return this.delete(NAMES_SPACE+".deleteUserCondit", condParse);
	}
	
	public int updatePwd(UserBean userLogin) {		
		return this.update(NAMES_SPACE+".updatePwd", userLogin);
	}
	
	public int addUserLogin(List<UserBean> list) {		
		return this.saveBatch(NAMES_SPACE+".addUserBacth", list);
	}
	
	public List<UserBean> listUser() {		
		return this.queryForList(NAMES_SPACE+".listUser");
	}
	
	/**
	 * <p>Description:获取用户参照总数<p>
	 * @author WJX
	 * @version 2014-11-24
	 * @modifier WJX
	 * @modifiDate 2014-11-24
	 * <p>modifiContent:<p>
	 */
	public int getRefUserCount(Map<String, Object> queryMap){
		return this.getCount(NAMES_SPACE+".getRefUserCount", queryMap);
	}
 
	 /**
	 * <p>Description:以分页方式查询用户参照列表<p>
	 * @author WJX
	 * @version 2014-11-24
	 * @modifier WJX
	 * @modifiDate 2014-11-24
	 * <p>modifiContent:<p>
	 */
	 public List<UserBean> listRefUser(Map<String, Object> queryMap,int currPage, int pageSize){
		 return this.queryForList(NAMES_SPACE+".listRefUser", queryMap, currPage, pageSize);
	 }

	@Override
	public UserBean findUserByEmail(String email) {
		return this.findObjectById(NAMES_SPACE+".findUserByEmail", email);
	}
}
